package com.binary.coder.gift.core.domain.ai.factory;

import com.alibaba.fastjson.JSONObject;
import com.binary.coder.gift.core.domain.ai.model.XingHuoModelInputParam;
import com.binary.coder.gift.core.domain.ai.model.XingHuoModeloutputParam;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.Arrays;

/**
 * @author atao
 * @version 1.0.0
 * @ClassName XingHuoFactory.java
 * @Description 星火模型工厂
 * @createTime 2024年07月12日 10:24:00
 */
public class XingHuoFactory {

    public static XingHuoModelInputParam buildXingHuoModelInputParam(String input) {
        XingHuoModelInputParam.Message message = new XingHuoModelInputParam.Message();
        message.setContent(input);
        message.setRole("user");
        return XingHuoModelInputParam.builder()
                .model("general")
                .stream(false)
                .temperature(1f)
                .messages(Arrays.asList(message))
                .build();
    }

    public static XingHuoModeloutputParam buildXingHuoModeloutputParam(String jsonString) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            XingHuoModeloutputParam result = objectMapper.readValue(jsonString, XingHuoModeloutputParam.class);
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return XingHuoModeloutputParam.builder().build();
    }

}
